package tbdp.tool.datasource;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author xbkaishui
 * @version $Id: DataSourceConfigFactory.java, v 0.1 2017-06-17 下午3:09 xbkaishui Exp $$
 */
public class DataSourceConfigFactory {

    public static ConcurrentHashMap<String, DataSourceConfig> datasourceMap = new ConcurrentHashMap<>();

    private static DataSourceLocater dataSourceLocater = new DataSourceLocater();

    public static DataSourceConfig getDataSourceConfig(String dataSourceName) {
        DataSourceConfig dataSourceConfig = datasourceMap.get(dataSourceName);
        if (dataSourceConfig == null) {

            dataSourceConfig = dataSourceLocater.locate(dataSourceName);

            putDataSourceConfig(dataSourceName,dataSourceConfig);
        }

        return dataSourceConfig;
    }

    public static DataSourceConfig putDataSourceConfig(String dataSourceName, DataSourceConfig dataSourceConfig) {
        return datasourceMap.putIfAbsent(dataSourceName, dataSourceConfig);
    }

}
